var rolelist = {
		
		curPage : 1,
		pageSize : 10,
		
		initPage : function(){
			rolelist.initBtn();
			rolelist.getRoleList(0);
		},
		
		initBtn : function(){
			$("#addBtn").click(function(){
				rolelist.addRole();
			});
			$("#qryBtn").click(function(){
				rolelist.getRoleList(0);
			});
		},
		getRoleList : function(pageIndex){
			var params = {};
			params['curPage'] = pageIndex + 1;
			params['pageSize'] = rolelist.pageSize;
			
			rolemanager.queryList({}, rolelist.getrolelist_Succ);
			rolelist.curPage = pageIndex + 1;
		},
		getrolelist_Succ : function(data){
			if(data && data.retCode == 0){
				var _html = '';
				if(data.data && data.data.length > 0){
					for(var key in data.data){
						var item = data.data[key];
						_html += '<tr><td class="tal"> '+((parseInt(rolelist.curPage)-1)*rolelist.pageSize + (parseInt(key)+1))+'</td>';
						_html += '<td class="tal">'+item.name+'</td>';
						_html += '<td class="tal">'+rolelist.getPowerDesc(item.power)+'</td>';
						_html += '<td class="tal">'+item.createtime+'</td>';
						if(item.account=='admin'){
							_html += '<td></td></tr>';
						}else{
							_html += '<td>';
							_html += ' <button class="btn btn-warning radius" onclick=\"javascript:rolelist.editRole('+item.id+');\">编辑</button>';
							_html += ' <button class="btn btn-danger radius" onclick="rolelist.dels('+item.id+')">删除</button></td></tr>';
						}
					}
					$('#rolelist').html(_html);
					if(data.page){
						util.paginationPage($('#rolelistpage'), data.page.totalPage, parseInt(data.page.curPage-1), rolelist.getRoleList,true);
					}
				}else{
					$('#rolelist').html('<tr  align="center"><td id="noData" colspan=10>暂无数据</td></tr>');
					$('#rolelistpage').html("");
				}
			}else{
				layer.msg("查询错误");
			}
		},
		
		getPowerDesc : function(power){
			var powers = power.split('');
			var desc = "";
			if(powers[0]=="1"){
				desc += "增  "
			}
			if(powers[1]=="1"){
				desc += "改 "
			}
			if(powers[2]=="1"){
				desc += "删 "
			}
			return desc || "无权限";
		},
		
		addRole : function(){
			util.loadContent(util.webpath+'role/addrole.html','contentDiv',{},function(){
				addrole.initPage();
			});
		},

		editRole : function(id){
			util.loadContent(util.webpath+'role/addrole.html','contentDiv',{},function(){
				addrole.id=id;
				addrole.initPage();
			});
		},
		
		dels:function(ids){
			layer.confirm("确认删除吗?", {
				  btn: ["确定","取消"] //按钮
				}, function(){
					rolemanager.deleteByIds({"ids":ids},function(){
						layer.msg("成功", {icon: 1});
						rolelist.getRoleList(0);
					});
				});
		},
		
};

